package es.mgil.whoWantsToBeAMillonaire.views;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.ViewConfiguration;

import com.google.android.maps.MapView;

/**
 * Extend Map View to add support to double click. When double click is pressed,
 * an automatic zoom is performed to the pointed zone
 * 
 * @author marc
 */
public class ExtendedMapView extends MapView {
	private long lastTouch = -1;

	public ExtendedMapView(Context context, String arg1) {
		super(context, arg1);
	}

	public ExtendedMapView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public ExtendedMapView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}

	@Override
	public boolean onInterceptTouchEvent(MotionEvent ev) {
		if (ev.getAction() == MotionEvent.ACTION_DOWN) {
			long thisTime = System.currentTimeMillis();
			if ((thisTime - lastTouch) < ViewConfiguration
					.getDoubleTapTimeout()) {
				getController().zoomInFixing((int) ev.getX(), (int) ev.getY());
				lastTouch = -1;
			} else {
				lastTouch = thisTime;
			}
		}

		return super.onInterceptTouchEvent(ev);
	}

}
